package com.kgc.scd.controller;


import com.kgc.scd.entity.ShopGoods;
import com.kgc.scd.service.BusyPurchaseService;
import com.kgc.scd.util.RedisUtils;
import com.kgc.scd.vo.ShopGoodsVO;
import com.kgc.scd.vo.ShopOrderVO;
import com.kgc.scd.vo.ShopUserBushVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created On : 2022/11/14.
 * <p>
 * Author : Administrator
 * <p>
 * Description: BusyPurchaseController
 */

@Slf4j
@RestController
@Api(tags = "抢购活动业务接口")
public class BusyPurchaseController {


    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private BusyPurchaseService busyPurchaseService;

    @ApiOperation(value = "判断商品是否为热销商品")
    @GetMapping("/judgeOrderIsBush")
    public ShopGoodsVO judgeOrderIsBush(String pid) {

        //判断商品是否为抢购商品
        ShopGoods shopGoods = busyPurchaseService.goodIsHot(pid);
        if (shopGoods == null) {
            return null;
        }

        ShopGoodsVO shopGoodsVO = new ShopGoodsVO();
        BeanUtils.copyProperties(shopGoods, shopGoodsVO);
        shopGoodsVO.setGoodsNumber(shopGoods.getGoodsNumber().toString());
        return shopGoodsVO;
    }


    @PostMapping("/insertBushDetail")
    @ApiOperation(value = "存入热狗数据库")
    public boolean insertBushDetail(@RequestBody ShopUserBushVO shopUserBushVO) {

        log.info("shopUserBushVO:{}", shopUserBushVO);

        return busyPurchaseService.insertBushDetail(shopUserBushVO);
    }

    @ApiOperation(value = "订单存入数据库,redis")
    @PostMapping("/createShopOrdertosave")
    public void createShopOrdertosave(@RequestBody ShopOrderVO shopOrderVO) {


        busyPurchaseService.insertShopOrderByEntity(shopOrderVO);
    }

}
